package com.gabry.goodkill.actor

import akka.actor.{Actor, ActorLogging}
import com.gabry.goodkill.protocol.Purchased

/**
  * Created by gabry on 2018/9/20 16:58
  */
class StateActor(goodNumber:Int) extends Actor with ActorLogging{
  private def goodLeftReceive(goodLeft:Int): Receive ={
    case _:Purchased if goodLeft >1 =>
      //log.info(s"商品被抢购，$goodLeft")
      context.become( goodLeftReceive( goodLeft - 1 ) )
    case _:Purchased =>
      log.info(s"商品已经被抢购完  ${System.currentTimeMillis()}")
  }
  override def receive: Receive = goodLeftReceive(goodNumber)
}
